/*
 * MIT License
 *
 * Copyright (c) 2023-present, tangli
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

package tony.test.redis

import org.slf4j.LoggerFactory
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.transaction.annotation.EnableTransactionManagement
import org.springframework.transaction.annotation.RollbackOn
import tony.core.annotation.EnableTonyBoot

/**
 * Redis 测试专用 Spring Boot 主配置类
 *
 * @author tony
 * @date 2025/07/01 17:00
 */
@SpringBootApplication
@EnableTransactionManagement(rollbackOn = RollbackOn.ALL_EXCEPTIONS)
@EnableTonyBoot
class TestRedisApplication {
    private val logger = LoggerFactory.getLogger(TestRedisApplication::class.java)

//    @Value($$"${spring.data.redis.port:6380}")
//    private lateinit var redisPort: String
//
//
//    private val redisServer: RedisServer by lazy {
//        RedisServer(redisPort.toInt())
//    }
//
//    /**
//     * 在 Spring 容器初始化前启动 embedded-redis
//     */
//    @PostConstruct
//    fun startEmbeddedRedis() {
//        val port = redisPort.toInt()
//        logger.info("Starting embedded Redis server on port: {}", port)
//        try {
//            redisServer.start()
//            logger.info("Embedded Redis server started successfully on port: {}", port)
//        } catch (e: Exception) {
//            logger.error("Failed to start embedded Redis server: {}", e.message, e)
//            throw e
//        }
//    }
//
//    /**
//     * 在 Spring 容器销毁前停止 embedded-redis
//     */
//    @PreDestroy
//    fun stopEmbeddedRedis() {
//        try {
//            redisServer.stop()
//            logger.info("Embedded Redis server stopped")
//        } catch (e: Exception) {
//            logger.error("Failed to stop embedded Redis server: {}", e.message, e)
//        }
//    }
}
